YAHOO.namespace("pingmob");

YAHOO.util.Event.onDOMReady(function () {
	YAHOO.pingmob.myEdit = function () {

        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;

        var returnList = function(p_oEvent) {
            window.location.href = "/agent/salesterminal";
        };
		
        var refreshRecord = function(p_oEvent) {
            window.location.reload();
        };

        var saveRecord = function(p_oEvent) {
        	if(checkContent()) {
        		document.forms["salesterminalForm"].submit();
        	}          
        };
        
        var checkContent = function() {
        	var salesYear = document.forms["salesterminalForm"]["salesYear"];
        	var salesAmount = document.forms["salesterminalForm"]["salesAmount"];
        	var terminalPhone = document.forms["salesterminalForm"]["terminalPhone"];
        	        	
        	if(salesAmount.value != "") {
        		var salesAmountReg = /^[0-9]+(.[0-9]+)?$/g;        		
        		if(isNaN(salesAmount.value) || !salesAmountReg.exec(salesAmount.value)) {
        			alert("填入数据是大于等于0的整数或小数！");
        			salesAmount.focus();
        			return false;
        		}
        	}        	
        	if(terminalPhone.value != "") {
        		var reg = /^[0-9]+([0-9]|[\-])+$/g;
        		if(terminalPhone.value.length < 7 || terminalPhone.value.length > 18 || !reg.exec(terminalPhone.value)) {
        			alert("请输入正确的电话号码！");
        			terminalPhone.focus();
        			return false;        			
        		}
        	}
        	return true;
        };

        var returnListBtn = new YAHOO.widget.Button("returnList", {onclick : {fn : returnList}});
        var refreshRecordBtn = new YAHOO.widget.Button("refreshRecord", {onclick : {fn : refreshRecord}});
        var saveRecordBtn = new YAHOO.widget.Button("saveRecord", {onclick : {fn : saveRecord}});
        
        $('#salesterminalForm').validationEngine({
            promptPosition:'centerRight',
            scroll: false
        });
        
        return {};		
		
	}();
		
});